//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "fn_dropAmmoBox.sqf"
#include <btc_macros.h>
TRACE_1("Start",_this);

private ["_vec","_has_ammo","_box","_box_pos","_handler"];
DEFAULT_PARAM(_vec,0,objNull);

_box = objNull;
if (IS_OBJECT(_vec) && {!(isNull _vec)}) then {
	_has_ammo = _vec getVariable ["BTC_AMMO_LOADED",false];
	TRACE_1("Has ammo",_has_ammo);
	if (_has_ammo) then {
		_vec setVariable ["BTC_AMMO_LOADED",false,true];
		sleep (1 + random(4));
		if (!([_vec] call FUNC(nearAmmoBox))) then {
			_box_pos = _vec modelToWorld [4,0,0.1];
			_box_pos set [2,0.1];
			TRACE_1("Box Pos",ARR_2(BTC_Ammo_Box_Type, _box_pos));
			_box = BTC_Ammo_Box_Type createVehicle _box_pos;
			if ((_box distance _box_pos) > 1.5) then {
				_box setPos _box_pos;
			};
			_box setVariable ["BTC_AMMO_BOX",true,true];
			clearBackpackCargoGlobal _box;
			clearMagazineCargoGlobal _box;
			clearWeaponCargoGlobal _box;
			clearItemCargoGlobal _box;
			["BTCR_pveh_vec",[200,BTC_side,_box,player]] call FUNC(callEvent);
			hint (localize "STR_BTC_AMMO_DROPPED");
		} else {
			hint (localize "STR_BTC_BOX_ALREADY_DROPPED");
		};
	} else {
		hint (localize "STR_BTC_BOX_ALREADY_DROPPED");
	};
};
TRACE_1("End",_box);
